import './index.scss'
// import { searchAllDictionaries } from '@/api/public'

/**
 * 创建新组件之后，在all-can-use-components中添加
 * 必须应用 microCreateMinis
 * 数据必须以formData包含
 * */
import { microCreateMinis } from '../../minis'
import { loadMicroTemplate } from '@/api/shoppingMall/feature'
/** 头部配置*/
export default {
  name: 'micro-header-box',
  mixins: [microCreateMinis],
  props: {},
  data() {
    return {
      isChangeTemplate: false,
      headerActive:['1','2'],
      brandLevelList: '',
      formData: {
        title: '', // 页面名称
        pageDesc:'', // 页面描述
        pageStyle:'', // 页面样式
        bg:0, // 页面背景
        bgImage:'',
        bgColor:'#FFFFFF',
        pageClassify:0, // 页面分类
        pageShare:0, // 页面共享
        shareTitle:'', // 分享标题
        shareDesc:'',  // 分享描述
        shareList:[], // 分享方式
      },
      currentPageId: '',
      pageTemplateList: [],
      id: '',
      commonCheckFieldRules: 'checkData', // 当前组件默认的规则判断函数
      mySelfCheckRules: 'mySelfCheckFun'// 我自己的验证规则函数  比如弹窗之类的
    }
  },
  watch: {
    dialog(val) {
      if (val) {
        this.pageTemplateList = JSON.parse(JSON.stringify(this.pageTemplateList))
        this.pageStyleC()
      }
    }
  },
  components: {
    choosePageTemplate: () => import('@/components/choose-page-template/index.vue'),
  },
  computed: {
  },
  mounted() {
    const category = this.$route.query.category
    this.currentPageId = this.$route.query.id

    if (category === 0) {
      this.formData.category = category
    } else {
      this.formData.category = 10
    }
  },
  methods: {
    pageStyleC(){
      this.isChangeTemplate = true
      this.$refs.templateStyle.dialog = true
    },
    choosePageTemplateEnd($event){
      if($event.data){
        this.$confirm('模板将替换当前页面，确认导入吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          const templateItem = JSON.parse(JSON.stringify($event.data))
          this.formData.pageStyle = templateItem.templateName
          const templateId = templateItem.id
          const templateParam = {
              templateId: templateItem.id,
              pageId: this.currentPageId
          }
          loadMicroTemplate(templateParam).then(res => {
            this.$message.success('模板导入成功!')
            this.$emit('loadTemplateToPageFuncEnd', { data: templateParam })
          })
        })
      }
    },
    changeImg(){},
    /**
     * 开始验证
     * */
    checkData() {
      this.myCheckResult((this.formData.type !== ''))
      this.myCheckResult((this.formData.title !== ''))
    },
    /** 弹窗*/
    mySelfCheckFun() { // 可以选择调用默认规则判断
      this.showCheckForm()
      this.$message.error('请填写完整信息')
    }

  }
}
